import { dailyViewsIp , productAmazonButtonClick, articleDiscountClick, articleShareNum, productShareNum} from '@/api/kanban.js'
import { timeFormat } from '@/utils/index.js'
import store from '@/store'
const dailyViewsIpReq = function (path) {
  let store_site = store.state.site.curSite
  let params = {
    local_time: timeFormat(new Date()),
    site_id: store_site.id,
    site: store_site.site ,
    uri: path
  }
  dailyViewsIp(params).then(() =>{
    console.log('ip浏览统计', path)
  })
}

export const dailyViewsIpFunc = function(path) {
  let store_site = store.state.site.curSite
  if(store_site) {
    dailyViewsIpReq(path)
  } else {
    store.dispatch('ToggleSite').then(res=>{
      if(res){
        dailyViewsIpReq(path)
      }
    })
  }

}

export const productAmazonButtonClickFunc = function(product_name) {
  let store_site = store.state.site.curSite
  let params = {
    local_time: timeFormat(new Date()),
    site_id: store_site.id,
    site: store_site.site|| 'us',
    product_name: product_name
  }
  productAmazonButtonClick(params).then(() =>{
    console.log('统计每日产品击前往Amazon按钮次数', product_name)
  })
}

export const articleDiscountClickFunc = function(article_title, article_id, discount_product) {
  let store_site = store.state.site.curSite
  let params = {
    local_time: timeFormat(new Date()),
    site_id: store_site.id,
    site: store_site.site|| 'us',
    article_title: article_title,
    article_id: article_id,
    discount_product: discount_product
  }
  articleDiscountClick(params).then(() =>{
    console.log('统计每日优惠产品点击数', article_title, article_id, discount_product)
  })
}


export const articleShareNumFunc = function(share_way, article_title, article_id) {
  let store_site = store.state.site.curSite
  let params = {
    local_time: timeFormat(new Date()),
    site_id: store_site.id,
    site: store_site.site|| 'us',
    share_way: share_way,
    article_title: article_title,
    article_id: article_id
  }
  articleShareNum(params).then(() =>{
    console.log('统计文章分享', share_way, article_id, article_title)
  })
}

export const productShareNumFunc = function(share_way, product_model_name) {
  let store_site = store.state.site.curSite
  let params = {
    local_time: timeFormat(new Date()),
    site_id: store_site.id,
    site: store_site.site|| 'us',
    share_way: share_way,
    product_model_name: product_model_name,
  }
  productShareNum(params).then(() =>{
    console.log('统计文章分享', share_way, product_model_name)
  })
}



